I have a stclass object which i am initializing in PHP code.
The object returns
object(stdClass)[238]
public '0' => string 'Jun 20, 2012 03:02 PM' (length=21)
public '1' => string 'Jun 20, 2012 03:26 PM' (length=21)
public '2' => string 'Jun 21, 2012 01:12 PM' (length=21)
on doing var_dum($myObjectName)
I am passing this to smarty template where i need to access values of stdClass object at index [i] based on a javascript variable .
I have tried several of these:
{/literal} {$myObjectName}{literal}
{/literal} {$myObjectName.0}{literal}
{/literal} {$myObjectName.'0'}{literal}
{/literal} {$myObjectName.'myLocalJSVariable'}{literal}
but i am not bale to fetch value of Object at particular index
rodneyrehm :
May I suggest you use json_encode() to dump your data to json, save that to something accessible to javascript, and then access your data from javascript?\n\n{$myObjectName->javaScriptVariable} sounds just like you were trying to access some client data on the server, or some server data on the client - which is not possible unless you provide the data.",
2012-06-22T14:31:56
lorenzo-s :
Did you tried {$myObjectName->0}?\n\nIf you want to use it the way you use arrays, you must pass an array version of the object to Smarty:\n\n$smarty->assign('myObjectName', get_object_vars($obj));\n\n\nThe get_object_vars() method returns a named array of all properties from an object.",
2012-06-21T20:21:48